﻿using System;
namespace Kis.Xroad.Eu {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="SequenceNullabilityOfUserDefined", Namespace="http://kis.x-road.eu/", Target=typeof(SequenceNullabilityOfUserDefined))]
    public class SequenceNullabilityOfUserDefinedSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected SequenceNullabilityOfUserDefined clazz;
        
        public SequenceNullabilityOfUserDefinedSerializer(SequenceNullabilityOfUserDefined clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("DegreesNillable");
            if (clazz.DegreesNillable!=null) {
                Writer.WriteString(clazz.DegreesNillable.ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("DegreesNonNillable");
            if (clazz.DegreesNonNillable!=null) {
                Writer.WriteString(clazz.DegreesNonNillable.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : DegreesNonNillable");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("GengerNil");
            if (clazz.GengerNil!=null) {
                Writer.WriteString(clazz.GengerNil.ToString());
            }
            else {
                Writer.WriteAttributeString("xsi", "nil", null, "1");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement("GengerNonNil");
            if (clazz.GengerNonNil!=null) {
                Writer.WriteString(clazz.GengerNonNil.ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : GengerNonNil");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="DegreesNillable") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.DegreesNillable = new global::Kis.Xroad.Eu.PositiveCelcius(Reader.ReadElementString("DegreesNillable"));
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>SequenceNullabilityOfUserDefined>DegreesNillable", Reader.LocalName);
            }
            if (Reader.LocalName=="DegreesNonNillable") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>SequenceNullabilityOfUserDefined>DegreesNonNillable");
                }
                clazz.DegreesNonNillable = new global::Kis.Xroad.Eu.PositiveCelcius(Reader.ReadElementString("DegreesNonNillable"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>SequenceNullabilityOfUserDefined>DegreesNonNillable", Reader.LocalName);
            }
            if (Reader.LocalName=="GengerNil") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.GengerNil = new global::Kis.Xroad.Eu.Gender(Reader.ReadElementString("GengerNil"));
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>SequenceNullabilityOfUserDefined>GengerNil", Reader.LocalName);
            }
            if (Reader.LocalName=="GengerNonNil") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>SequenceNullabilityOfUserDefined>GengerNonNil");
                }
                clazz.GengerNonNil = new global::Kis.Xroad.Eu.Gender(Reader.ReadElementString("GengerNonNil"));
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>SequenceNullabilityOfUserDefined>GengerNonNil", Reader.LocalName);
            }
        }
    }
}
